package com.njitt.bysj.controller;

import com.njitt.bysj.base.BaseController;
import com.njitt.bysj.base.ResultInfo;
import com.njitt.bysj.bean.ProjectPurchaseBean;
import com.njitt.bysj.bean.ProjectQualityBean;
import com.njitt.bysj.bean.PurchaseRequestBean;
import com.njitt.bysj.bean.QualityHistoryBean;
import com.njitt.bysj.query.HistoryQuery;
import com.njitt.bysj.query.QualityQuery;
import com.njitt.bysj.srevice.ProjectQualityService;
import com.njitt.bysj.srevice.PurchaseService;
import com.njitt.bysj.utils.AssertUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.net.Inet4Address;
import java.sql.ResultSet;
import java.util.List;
import java.util.Map;

/**
 * @description:
 * @author: wyj
 * @time: 2022/4/19 16:39
 */
@Controller
@RequestMapping("quality")
public class QualityController extends BaseController {

    @Resource
    private ProjectQualityService projectQualityService;

    @Resource
    private PurchaseService purchaseService;

    @RequestMapping("toQualityPage")
    public String toQualityPage() {
        return "quality/qualityPage";
    }

    @RequestMapping("selectByParamsWithPurchase")
    @ResponseBody
    public Map<String, Object> selectByParamsWithPurchase(QualityQuery query) {
        return projectQualityService.selectByParamsWithPurchase(query);
    }

    @RequestMapping("arrivalPurchaseRequestOrder")
    @ResponseBody
    public ResultInfo arrivalPurchaseRequestOrder(@RequestBody List<PurchaseRequestBean> requestBeanList) {
        projectQualityService.arrivalPurchaseRequestOrder(requestBeanList);
        return success("success");
    }

    @RequestMapping("toAssignPage")
    public String toAssignPage(Integer id, HttpServletRequest request) {
        AssertUtil.isTrue(id == null, "指派失败");
        ProjectQualityBean qualityBean = projectQualityService.selectByPrimaryKey(id);
        request.setAttribute("quality", qualityBean);
        return "quality/AssignPage";
    }

    @RequestMapping("addEmpToQuality")
    @ResponseBody
    public ResultInfo addEmpToQuality(ProjectQualityBean qualityBean) {
        /**
         * @description: 指派质检员
         * @return:  * @param qualityBean
         * @author:
         * @time: 2022/4/19 21:37
         */
        projectQualityService.updateEmpToQuality(qualityBean);
        return success("success");
    }

    @RequestMapping("toAddQualityResultPage")
    public String toAddQualityPage(Integer id, HttpServletRequest request) {
        ProjectQualityBean projectQualityBean = projectQualityService.selectByPrimaryKey(id);
        request.setAttribute("quality", projectQualityBean);
        return "quality/addQualityResult";
    }

    @RequestMapping("addQualityResult")
    @ResponseBody
    public ResultInfo addQualityResult(QualityHistoryBean qualityHistoryBean) {
        projectQualityService.addQualityResult(qualityHistoryBean);
        return success("success");
    }

    @RequestMapping("selectByParamsWithQualityHistory")
    @ResponseBody
    public Map<String, Object> selectByParamsWithPurchase(HistoryQuery query) {
        /**
         * @description: 质检历史
         * @return:  * @param query
         * @author:
         * @time: 2022/4/20 11:30
         */
        return projectQualityService.selectByParamsWithQualityHistory(query);
    }

    @RequestMapping("toQualityHistory")
    public String toQualityHistory() {
        return "quality/qualityHistory";
    }

    @RequestMapping("selectByParamsWithEntryHistoryHistory")
    @ResponseBody
    public Map<String, Object> selectByParamsWithEntryHistoryHistory(HistoryQuery query) {
        /**
         * @description: 采购入库单 即审批同意历史
         * @return:  * @param
         * @author:
         * @time: 2022/4/21 9:52
         */
        return projectQualityService.selectByParamsWithEntryHistoryHistory(query);

    }

    @RequestMapping("toProductionQuality")
    public String toProductionQuality() {
        /**
         * @description: 生产质检
         * @return:  * @param
         * @author:
         * @time: 2022/4/23 0:18
         */
        return "quality/productionQuality";
    }

    @RequestMapping("selectByParamsWithProduce")
    @ResponseBody
    public Map<String, Object> selectByParamsWithProduce(QualityQuery query) {
        return projectQualityService.selectByParamsWithProduce(query);
    }

    @RequestMapping("assignProduceProjectPage")
    public String assignProduceProjectPage(Integer id, HttpServletRequest request) {
        /**
         * @description:
         * @return:  * @param id
         * @param request
         * @author:
         * @time: 2022/4/24 10:55
         */
        ProjectQualityBean qualityBean = projectQualityService.selectByPrimaryKey(id);
        request.setAttribute("quality", qualityBean);
        return "quality/assignProduceProjectPage";
    }

    @RequestMapping("addEmpToProduceQuality")
    @ResponseBody
    public ResultInfo addEmpToProduceQuality(ProjectQualityBean qualityBean) {
        /**
         * @description:产成品添加质检员
         * @return:  * @param qualityBean
         * @author:
         * @time: 2022/4/24 11:22
         */
        projectQualityService.addEmpToProduceQuality(qualityBean);
        return success("success");
    }

    @RequestMapping("toAddProduceQualityResultPage")
    public String toAddProduceQualityResultPage(Integer id ,HttpServletRequest request){
        ProjectQualityBean projectQualityBean = projectQualityService.selectByPrimaryKey(id);
        request.setAttribute("quality", projectQualityBean);
        return "quality/produceQualityResult";
    }

    @RequestMapping("addProduceQualityResult")
    @ResponseBody
    public ResultInfo addProduceQualityResult(QualityHistoryBean qualityHistoryBean){
         projectQualityService.addProduceProjectQualityResult(qualityHistoryBean);
         return success("success");
    }
    @RequestMapping("toProduceQualityHistory")
    public String toProduceQualityHistory(){
         return "quality/toProduceQualityHistory";
    }

    @RequestMapping("selectByParamsWithProduceQualityHistory")
    @ResponseBody
    public Map<String, Object>selectByParamsWithProduceQualityHistory(HistoryQuery query){
        return projectQualityService.selectByParamsWithProduceQualityHistory(query);
    }

}
